------------------------------------------------------------

All code was run on Mac OS X. My system settings:

macOS Mojave
Version 10.14.3
MacBook Pro (15-inch, 2018)
Processor Name: Intel Core i7
Processor Speed:  2.2 GHz
Number of Processors: 1
Total Number of Cores:  6
L2 Cache (per Core):  256 KB
L3 Cache: 9 MB
Memory: 16 GB

I used R version 3.5.0. Required R packages are: 

arm
car
colorout
data.table
doMC
foreach
gtools
mapproj
maps
maptools
openxlsx
plotrix
rgdal
RPostgreSQL
rstan
sp
sqldf
stringr

You will also have to install a database to your computer or to the cloud, to run the code. I used PostgreSQL 11, installed on the same Mac machine. Instructions on how to install and prep the database can be found in postgresql_installation_instructions.txt. 

------------------------------------------------------------

The data files are: 

data/yg_pamrp_surveydata.txt: survey data
data/yg_pamrp_fips2012results.txt: county results from 2012
data/yg_pamrp_state2012results.txt: state results from 2012
data/yg_pamrp_poststrat_sample.csv.zip: one percent sample of voter registration database with relevant variables
data/st99_d00_shp: folder containing state shapefiles
data/co99_d00_shp: folder containing county shapefiles
data/2012_exit_polls.xlsx: relevant data from 2012 exit polls

------------------------------------------------------------

Replication code includes the following R scripts.

00_run_scripts.sh: runs all of the following R scripts
scripts/01_stan_model.R: read in survey data, compile and run the model
scripts/02_score_in_database.R: score the model in the database, i.e., produce yhats (before intercept correction)
scripts/03_county_intercept_correction.R: compute county-level intercept shifts and apply them, creating final yhats
scripts/04_figures_1_to_4.R: some plots for the paper
scripts/05_figures_5_to_7.R: some other plots for the paper

The plots created using these scripts will not exactly match the figures in the paper. We do not have permission to share the entire voter registration database used in the paper, so we agreed with the journal to provide a 1% sample for replication purposes. The only place where there are substantial differences is in Figure 7. The overall trends are the same, but trends are weaker/noisier in the 1% sample -- this is because the graphs examine subgroup trends within counties, which are noisier with the smaller sample size. This is discussed in the appendix of the paper; the figure in the appendix is not included for replication, because it explicitly compares the results from the full database to the 1% sample. 

Output figures are in the figures folder. Hand-made tables are in the tables folder. Fonts used for PDFs are in the fonts folder. 

------------------------------------------------------------

Runtimes for scripts were as follows:

01_stan_model.R: 705m57.208s
02_score_in_database.R: 21m28.073s
03_county_intercept_correction.R: 31m59.138s
04a_figures_1_to_4.R: 0m43.098s
05a_figures_5_to_7.R: 0m26.212s
